class Axe1_ extends Axe;

var float NextIronTime;

replication
{
	reliable if(Role < ROLE_Authority)
		DoLunge;
}

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();
	NextIronTime = Level.TimeSeconds + 3.0;
}

simulated exec function ToggleIronSights()
{
	local KFPlayerReplicationInfo KFPRI;
	
	//this functionality is available to berserkers only
	KFPRI = KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo);
	if (KFPRI == none || KFPRI.ClientVeteranSkill != Class'SRVetBerserker')
		return;
		
	if (
		NextIronTime <= Level.TimeSeconds &&
		!FireMode[0].bIsFiring && FireMode[0].NextFireTime < Level.TimeSeconds &&
		!FireMode[1].bIsFiring && FireMode[1].NextFireTime < Level.TimeSeconds
		)
	{
		if (Instigator != none && Instigator.Physics != PHYS_Falling)
		{
			DoLunge();
			if (ROLE < ROLE_AUTHORITY) //client-side fx, essentially
				FireMode[1].ModeDoFire();
				
			NextIronTime=Level.TimeSeconds+3.0;
		}
	}
}

simulated function DoLunge()
{
	local rotator VR; //ViewRotation
	local vector DirMomentum;
	
	VR = Instigator.Controller.GetViewRotation();

	DirMomentum.X = 325.0 * (1.0 + KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo).ClientVeteranSkill.static.GetMeleeMovementSpeedModifier(KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo)));
	DirMomentum.Y = 0.0;
	DirMomentum.Z = 275.0; //325.0; //default kfhumanpawn jump height
	VR.Pitch=0;
			
	FireMode[1].ModeDoFire();
		
	Instigator.AddVelocity(DirMomentum >> VR);
	
//	KFGameType(Level.Game).DramaticEvent(0.01);
	DKGameType(Level.Game).DebugMessage("KFPCServ = "$string(KFPCServ(Instigator.Controller)));
	KFPCServ(Instigator.Controller).AddZedTimeCharge(0.10);
	SRHumanPawn(Instigator).ConsumeStamina(7.5);
}

function bool CanOmitKnifeChoose()
{
	local Inventory Inv;
	
	for(Inv=Instigator.Inventory; Inv!=none; Inv=Inv.Inventory)
	{
		if ( SRMeleeGun(Inv) != none )
		{
			if ( Inv.Name != Self.Name && SRMeleeGun(Inv).bBetterThanKnife )
			{
				return true;
			}
		}
		else if ( KFMeleeGun(Inv) != none )
		{
			if ( Inv.Name != Self.Name && Knife(Inv) == none && Syringe(Inv) == none
				&& Welder(Inv) == none && Axe(Inv) == none && Chainsaw(Inv) == none )
			{
				return true;
			}
		}
	}
	
	return false;
}

simulated function Weapon PrevWeapon(Weapon CurrentChoice, Weapon CurrentWeapon)
{
	if ( CanOmitKnifeChoose() && Knife(Inventory) != none )
	{
		return Inventory.PrevWeapon(CurrentChoice,CurrentWeapon);
	}
		
	return Super.PrevWeapon(CurrentChoice,CurrentWeapon);
}

simulated function Weapon NextWeapon(Weapon CurrentChoice, Weapon CurrentWeapon)
{
	if ( CanOmitKnifeChoose() && Knife(Inventory) != none )
	{
		return Inventory.NextWeapon(CurrentChoice,CurrentWeapon);
	}

	return Super.NextWeapon(CurrentChoice,CurrentWeapon);
}

defaultproperties
{
     FireModeClass(0)=Class'AxeFireNew'
     FireModeClass(1)=Class'AxeFireNewB'
     PickupClass=Class'Axe1Pickup'
     AttachmentClass=Class'KFMod.AxeAttachment'
}
